<?php defined('_JEXEC') or die('Restricted access'); ?>
<script language="javascript" type="text/javascript">
    function tableOrdering( order, dir, task ) {
        var form = document.adminForm;

        form.filter_order.value 	= order;
        form.filter_order_Dir.value	= dir;
        document.adminForm.submit( task );
    }
</script>
<h1><? echo JText::_('List of active polls'); ?></h1>
<form action="index.php?option=com_joomlacommunitypolls" method="post" name="adminForm">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="2%" height="20" style="" class="sectiontableheader">
                <?php echo JText::_('Num'); ?>
            </td>
            <td width="50%" class="sectiontableheader">
                <?php echo JHTML::_('grid.sort', JText::_('TITLE_POLL_TITLE'), 'p.title', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
            </td>
            <td width="13" class="sectiontableheader" style="text-align:center;" nowrap="nowrap">
                <?php echo JHTML::_('grid.sort',JText::_('TITLE_POLL_VOTES'), 'p.votes', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
            </td>
            <td width="20" class="sectiontableheader" style="text-align:center;" nowrap="nowrap">
                <?php echo JHTML::_('grid.sort', JText::_('TITLE_POLL_AUTHOR'), 'u.username', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
            </td>
            <td width="15" class="sectiontableheader" style="text-align:center;" nowrap="nowrap">
                <?php echo JHTML::_('grid.sort', JText::_('TITLE_POLL_DATE'), 'p.created', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
            </td>
        </tr>
        <?php
        $k = 0;

        for ($i=0, $n=count( $this->items ); $i < $n; $i++)
        {
            $row = &$this->items[$i];
            $link = JRoute::_( 'index.php?option=com_joomlacommunitypolls&controller=polls&task=viewpoll&poll_id='. $row->id );

        ?>
        <tr class="sectiontableentry<?php echo $k + 1; ?>">
            <td>
                <?php echo $this->pagination->getRowOffset( $i ); ?>
            </td>
            <td>
                <a href="<?php echo $link;  ?>"><?php echo $row->title; ?></a>
            </td>
            <td align="center">
                <?php echo $row->votes; ?>
            </td>
            <td align="center">
                <?php echo $row->username; ?>
            </td>
            <td align="center">
                <?php echo $row->created; ?>
            </td>
        </tr>
        <?php
            $k = 1 - $k;
        }
        ?>
        <tr>
            <td align="center" colspan="5" class="sectiontablefooter">
                <?php echo $this->pagination->getPagesLinks(); ?>
            </td>
        </tr>
        <tr>
            <td colspan="5" align="right" class="pagecounter">
                <?php echo $this->pagination->getPagesCounter(); ?>
            </td>
        </tr>
    </table>

    <input type="hidden" name="option" value="com_joomlacommunitypolls" />
    <input type="hidden" name="task" value="viewpoll" />
    <input type="hidden" name="boxchecked" value="0" />
    <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
    <input type="hidden" name="filter_order_Dir" value="" />
    <?php echo JHTML::_( 'form.token' ); ?>
</form>
<br />